{% extends "base.html" %}
{% set title = "教师列表" %}
{% block content %}
    <h2>教师信息</h2>

    <table class="table">
        <thead>
            <tr>
                <th>ID</th>
                <th>姓名</th>
                <th>年龄</th>
                <th>性别</th>
                <th>职称</th>
                <th>专业</th>
                <th>密码</th>
                <th>操作</th>
            </tr>
        </thead>
        <tbody>
            {% for teacher in teachers %}
            <tr>
                <td>{{ teacher.id }}</td>
                <td>{{ teacher.username }}</td>
                <td>{{ teacher.age }}</td> 
                <td>{{ teacher.gender }}</td>
                <td>{{ teacher.title }}</td>
                <td>{{ teacher.major.name if teacher.major else '无专业' }}</td>
                <td>{{ teacher.password }}</td>
                <td>
                    {% if is_admin or ( session['role'] == 'teacher' and teacher.id == session['uid']) %}
                    <a href="{{ url_for('edit_teacher', id=teacher.id) }}" class="btn btn-warning btn-sm">编辑</a>
                    {% if is_admin %}
                    <a href="{{ url_for('delete_teacher', id=teacher.id) }}" class="btn btn-danger btn-sm">删除</a>
                    {% endif %}
                    {% endif %}
                </td>
            </tr>
            {% endfor %}
        </tbody>
    </table>
    {% if is_admin %}
    <a href="{{ url_for('add_teacher') }}" class="btn btn-primary mb-3">添加教师</a><br>
    {% endif %}
    <a href="{{ url_for('logout') }}" class="btn btn-secondary mb-3">登出</a>
{% endblock %}